﻿package
	{
	import flash.display.MovieClip;
	
	public class Equipment extends Item
		{
		var equipmentAttributes:Attribute;
		var equipMC:MovieClip;
		var equipMCDuplicate:MovieClip;
		var equipPart:String;
		var itemType:String;
		
		public function Equipment(itemName:String, itemDesc:String, itemIcon:String, equipPart:String, stats:Array)
			{
			super(itemName, itemDesc, 1, MainClass.loadMC(itemIcon));
			this.itemType = itemIcon;
			this.equipPart = equipPart;
			equipMC = MainClass.loadMC(itemIcon);
			this.addChild(equipMC);
			equipMC.gotoAndStop("icon");
			equipmentAttributes = new Attribute(stats);
			}
		
		public function cloneEquip():Equipment
			{
			var newEquip:Equipment = new Equipment(itemName, itemDesc, itemType, equipPart, equipmentAttributes.modificator);
			return newEquip;
			}
		
		public function equip(player:Player)
			{
			if (equipPart == "Weapon")
				{
				player.torso.rightHand.addChild(equipMC);
				equipMC.gotoAndStop(1);
				equipMC.y = 30;
				}
			else if (equipPart == "Hat")
				{
				player.head.addChild(equipMC);
				equipMC.gotoAndStop(1);
				}
			else if (equipPart == "Gloves")
				{
				player.torso.rightHand.addChild(equipMC);
				equipMCDuplicate = MainClass.cloneMC(equipMC);
				equipMCDuplicate.gotoAndStop(1);
				player.torso.leftHand.addChild(equipMCDuplicate);
				equipMC.gotoAndStop(1);
				}
			else if (equipPart == "Shoulders")
				{
				player.torso.addChild(equipMC);
				equipMC.gotoAndStop(1);
				}
			else
				{
				trace ("Incorect equip part value... "+equipPart);
				}
			
			if (equipmentAttributes!=null)
				equipmentAttributes.applyModification(player);
			player.getStats(false);
			}
		
		public function unEquip(player:Player)
			{
			if (equipPart == "Weapon")
				{
				player.torso.rightHand.removeChild(equipMC);
				}
			else if (equipPart == "Hat")
				{
				player.head.removeChild(equipMC);
				}
			else if (equipPart == "Gloves")
				{
				player.torso.rightHand.removeChild(equipMC);
				player.torso.leftHand.removeChild(equipMCDuplicate);
				}
			else if (equipPart == "Shoulders")
				{
				player.torso.removeChild(equipMC);
				}
			else
				{
				trace ("Incorect unequip part value... "+equipPart);
				}
			if (equipmentAttributes!=null)
				equipmentAttributes.removeModification(player);
			player.getStats(false);
			}
		
		
		}
	}